home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / AppleEvents / Records / ConstAEMember.cp < prev    next >
Text File  |  2000-06-23  |  2KB  |  106 lines

  1. // ConstAEMember.cp
  2.  
  3. #ifndef ConstAEMember_h
  4. #include "ConstAEMember.h"
  5. #endif
  6. #ifndef OSError_h
  7. #include "OSError.h"
  8. #endif
  9. #ifndef Buffer_h
  10. #include "Buffer.h"
  11. #endif
  12. #ifndef AEStruct_h
  13. #include "AEStruct.h"
  14. #endif
  15.  
  16. #include <Errors.h>
  17.  
  18. bool ConstAEMember::Exists() const
  19.   {
  20.     Assert( !Record().IsNull() );
  21.     DescType type;
  22.     int32 size;
  23.     
  24.     OSErr error = AESizeOfKeyDesc( &record, key.Key(), &type, &size );
  25.     
  26.     if ( error != noErr && error != errAEDescNotFound )
  27.         throw OSError( error );
  28.     
  29.     return error == noErr;
  30.   }
  31.  
  32. uint32 ConstAEMember::Length() const
  33.   {
  34.     Assert( !Record().IsNull() );
  35.     DescType type;
  36.     int32 size;
  37.     ThrowOSError( AESizeOfKeyDesc( &record, key.Key(), &type, &size ) );
  38.     Assert( size >= 0 );
  39.     return size;
  40.   }
  41.  
  42. AEType ConstAEMember::Type() const
  43.   {
  44.     Assert( !Record().IsNull() );
  45.     DescType type;
  46.     int32 size;
  47.     ThrowOSError( AESizeOfKeyDesc( &record, key.Key(), &type, &size ) );
  48.     return AEType( type );
  49.   }
  50.  
  51. void ConstAEMember::operator>>( Data out ) const
  52.   {
  53.     Assert( !Record().IsNull() );
  54.     DescType type;
  55.     int32 size;
  56.     ThrowOSError( AEGetKeyPtr( &record,
  57.                                         key.Key(),
  58.                                         typeWildCard,
  59.                                         &type,
  60.                                         out.Start(),
  61.                                         out.Length(),
  62.                                         &size ) );
  63.   }
  64.  
  65. void ConstAEMember::operator>>( Buffer& out ) const
  66.   {
  67.     Assert( !Record().IsNull() );
  68.     DescType type;
  69.     int32 size;
  70.     ThrowOSError( AEGetKeyPtr( &record,
  71.                                         key.Key(),
  72.                                         typeWildCard,
  73.                                         &type,
  74.                                         out.Unused().Start(),
  75.                                         out.Unused().Length(),
  76.                                         &size ) );
  77.     Assert( size >= 0 );
  78.     out.AdvanceMark( size );
  79.   }
  80.  
  81. void ConstAEMember::Get( AEType desiredType, Data out ) const
  82.   {
  83.     Assert( !Record().IsNull() );
  84.     DescType actualType;
  85.     int32 actualSize;
  86.     ThrowOSError( AEGetKeyPtr( &record,
  87.                                         key.Key(),
  88.                                         desiredType.Type(),
  89.                                         &actualType,
  90.                                         out.Start(),
  91.                                         out.Length(),
  92.                                         &actualSize ) );
  93.  
  94.     Assert( actualType == desiredType.Type() );
  95.     Assert( actualSize == out.Length() );
  96.   }
  97.  
  98. AEDescriptor::AEDescriptor( const ConstAEMember& member, AEType desired )
  99.   {
  100.     Assert( !member.Record().IsNull() );
  101.     ThrowOSError( AEGetKeyDesc( &member.Record(),
  102.                                          member.Key().Key(),
  103.                                          desired.Type(),
  104.                                          this ) );
  105.   }
  106.